﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Data;
using System.Web.UI.WebControls;
using CS424_9pts.Control;
using System.Data.SqlClient;

namespace CS424_9pts
{
    public class Global : System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            
            //MailMan.SendMail("dinh.ngoclan@yahoo.com", "cocon", "have a good day");
            //SqlConnection conn = new SqlConnection( System.Configuration.ConfigurationManager.ConnectionStrings["CarManagementConnectionString"].ToString() );
            //SqlCommand command = new SqlCommand("SELECT        aspnet_Users.UserName, aspnet_Membership.Email, Maintenance.SpanTimeMaintenace, Contract.DatePurchased FROM            Contract INNER JOIN aspnet_Users ON Contract.StaffID = aspnet_Users.UserId AND Contract.CustomerID = aspnet_Users.UserId INNER JOIN Maintenance ON Contract.ContractID = Maintenance.ContractID INNER JOIN aspnet_Membership ON aspnet_Users.UserId = aspnet_Membership.UserId WHERE        (Contract.DatePurchased = (GetDay() - Contract.DatePurchased) / '30 modulus Maintenance.SpanTimeMaintenace = 0')", conn);
            //SqlDataReader dr = command.ExecuteReader();
            //DataTable dt = new DataTable();
            //dt.Load(dr);
            //SendMail(dt);
        }

        void SendMail(DataTable dt)
        {
            foreach (DataRow dr in dt.Rows)
            {
                //MailMan.SendMail(dr["Email"].ToString(), dr["UserName"].ToString(), "Today, you can get your car back");
            }
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }

    }
}
